﻿@*@model PagedList.IPagedList<Infinity.BusinessLayer.CourseList>
    @using PagedList.IPagedList;*@
@model IPagedList<Infinity.BusinessLayer.CourseList>
@using PagedList;
@using PagedList.Mvc;

<table>
    <tr>
        <th>
                CourseID
            </th>
            <th>
                Course_Name
            </th>
            <th>
                Official_crs_hrs
            </th>
            <th>
                Exam
            </th>
            <th>
                Material
            </th>
            <th>
                Certificate
            </th>

        @*<th>
            @Html.DisplayNameFor(model => model.CourseID)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Course_Name)
        </th>
        <th>
            @Html.DisplayNameFor(modelItem => modelItem.Official_crs_hrs)
        </th>
        <th>
            @Html.DisplayNameFor(modelItem => modelItem.Exam)
        </th>
        <th>
            @Html.DisplayNameFor(modelItem => modelItem.Material)
        </th>
        <th>
            @Html.DisplayNameFor(modelItem => modelItem.Certificate)
        </th>*@
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.CourseID)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Course_Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Official_crs_hrs)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Exam)
            </td>
            <td>
                @{
                    
        Infinity.Models.InfinityEntities context = new Infinity.Models.InfinityEntities();
        item.Certificate = context.course_material_certificate.Where(cc => cc.CourseID == item.CourseID).FirstOrDefault().certificate;
        item.Material = context.course_material_certificate.Where(cc => cc.CourseID == item.CourseID).FirstOrDefault().material;
      
                }
                @Html.DisplayFor(modelItem => item.Material)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Certificate)
            </td>
            <td>
            
                @Html.ActionLink("Edit", "EditeCourse", new { CrsID = item.CourseID }, new { @class = "buttonstyle" })
           
                
            </td>
            <td>
                <button class="DeleteCourse" value="@item.CourseID"> Delete</button>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
    }

</table>
<br />
<table>
    <tr>
        <td>@Html.PagedListPager(Model, page => Url.Action("Index", new { page, searchBy = Request.QueryString["searchBy"], searchfor = Request.QueryString["searchfor"] }))</td>
    </tr>
</table>


<script src="~/Content/js/jquery-1.11.2.min.js"></script>
<script>
 
    //----- delete Course--------------------------------------------
    $(document).ready(function () {
       
        $(".DeleteCourse").click(function (a) {
            
            var caller = $(this);
            var id = $(this).val();
            var x = $(this).hasClass('fromedite');

            if (confirm("Are you sure you want to delete")) {
                $.ajax({
                    type: "POST",
                    url: "/Managerial/Course/DeleteCourse",
                    data: { crsID: id },
                    success: function (list) {

                        if (x == true) {
                            location.href = '/Managerial/Course/Index';
                        }
                        else {
                            $('#CourseContainer').html(list);
                            alert("deleted Successfully");
                        }
                    },
                    error: function () {
                        alert("can't Delet it");
                    }
                });
            }
        })
    })

</script>


